package com.awcall.iot.controller;


import com.awcall.iot.common.ResponseResult;
import com.awcall.iot.model.AddressListGroup;
import com.awcall.iot.service.IAddressListGroupService;
import com.awcall.iot.service.IAddressListGroupService;
import com.awcall.iot.service.IStatementsService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import com.awcall.iot.common.BaseController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuhui
 * @since 2018-04-03
 */
@RestController
@RequestMapping("/admin/addressListGroup")
public class AddressListGroupController extends BaseController {

    @Autowired
    private IAddressListGroupService iAddressListGroupService;

    @Autowired
    private IStatementsService iStatementsService;

    @GetMapping("/index")
    public ResponseResult index(AddressListGroup addressListGroup, Page<AddressListGroup> page){

        EntityWrapper<AddressListGroup> entityWrapper = new EntityWrapper<>();

        if (StringUtils.isEmpty(addressListGroup.getName())){
            entityWrapper.like(AddressListGroup.NAME,addressListGroup.getName());
        }

        Page<AddressListGroup> addressListGroupPage = iAddressListGroupService.selectPage(page, entityWrapper);
        return new ResponseResult<>(addressListGroupPage);
    }

    @GetMapping("/list")
    public ResponseResult list(AddressListGroup addressListGroup){

        EntityWrapper<AddressListGroup> entityWrapper = new EntityWrapper<>();

        if (StringUtils.isEmpty(addressListGroup.getName())){
            entityWrapper.like(AddressListGroup.NAME,addressListGroup.getName());
        }

        List<AddressListGroup> addressListGroups = iAddressListGroupService.selectList(entityWrapper);

        return new ResponseResult<>(addressListGroups);
    }

    @GetMapping("/detail")
    public ResponseResult detail(AddressListGroup addressListGroup){

        AddressListGroup addressListGroup1 = addressListGroup.selectById();

        return new ResponseResult<>(addressListGroup1);
    }

    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody AddressListGroup addressListGroup){

        boolean insert = addressListGroup.insert();

        if (insert) {
            return new ResponseResult();
        } else {
            return new ResponseResult(1, "失败");
        }
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody AddressListGroup addressListGroup){

        boolean updateById = addressListGroup.updateById();

        if (updateById) {
            return new ResponseResult();
        } else {
            return new ResponseResult(1, "失败");
        }
    }

    @PostMapping("/delete")
    public ResponseResult delete(@RequestBody AddressListGroup addressListGroup){

        boolean deleteById = addressListGroup.deleteById();

        if (deleteById) {
            return new ResponseResult();
        } else {
            return new ResponseResult(1, "失败");
        }
    }
    
    

}
